* ==============================================================================
*
* Date:	Summer 2024
* Paper: Climate shocks, regional favoritism and trust in leaders: Insights from droughts in Africa
*
* This creates Table 2			
*
* ==============================================================================


*	Frequency of trust response of different categories

* Open dataset

cd $PATH
use tr_rep, clear
*keep if precision_code<=3 

* Table 
global tabname "frequencies"

qui fre tr_pres_ord
* matrix list r(valid)
matrix x = r(valid)/r(N_valid)*100
matrix z1=round(x[1,1], 1)
matrix z2=round(x[2,1], 1)
matrix z3=round(x[3,1], 1)
matrix z4=round(x[4,1], 1)
matrix z5=100
matrix A1 = z1\ z2\z3\z4\z5
matrix list A1

qui fre tr_rel_ord
matrix x = r(valid)
matrix z1=x[1,1]
matrix z2=x[2,1]
matrix z3=x[3,1]
matrix z4=x[4,1]
matrix z5=r(N)
matrix A0 = z1\ z2\z3\z4\z5
matrix list A0

matrix A = A0, A1
matrix rownames A = not little some alot total
matrix colnames A = nobs share
matrix list A

*global tabname "rawshares"

*0=Not at all, 1=Just a little, 2=Somewhat, 3=A lot
gen not =1
label var not "Not at all"

gen little =1
label var little "Just a little"

gen some =1
label var some "Somewhat"

gen alot =1
label var alot "A lot"

gen total=1
label var total "Total"

matrix B = A[1..5, 1..2]
matrix list B


/*

B[5,2]
          nobs   share
   not    5476    18.3
little   13555    22.2
  some   22019      23
  alot   61810    36.5
 total  226442     100


*/


esttab  matrix(B, fmt(%9.0fc %9.0f)) using $OUTPATH/$tabname.rtf, title("Table 2. Frequency of Trust Responses.") ///
collabels(N %, lhs({\i Trust response})) addnotes("{\i Notes:} Frequency of each response. All respondents from Afrobarometer survey rounds 2-7 are included. The question asked is 'How much do you trust each of the following, or haven't you heard enough about them to say: The President/Prime Minister?' Pre-defined answers and corresponding values are: Not at all (0), Just a little (1), Somewhat (2), and A lot (3). ") ///
noobs nonumber nomtitles label compress nogaps replace 



* Open dataset

cd $PATH
use tr_rep, clear
*keep if precision_code<=3 

* Table 
global tabname "frequencies"

qui fre tr_pres_ord
* matrix list r(valid)
matrix x = r(valid)/r(N_valid)*100
matrix z1=round(x[1,1], 1)
matrix z2=round(x[2,1], 1)
matrix z3=round(x[3,1], 1)
matrix z4=round(x[4,1], 1)
matrix A1 = z1\ z2\z3\z4
matrix list A1

qui fre tr_rel_ord
matrix x = r(valid)
matrix z1=x[1,1]
matrix z2=x[2,1]
matrix z3=x[3,1]
matrix z4=x[4,1]
matrix A0 = z1\ z2\z3\z4
matrix list A0

matrix A = A0, A1
matrix rownames A = not little some alot
matrix colnames A = nobs share
matrix list A

*global tabname "rawshares"

*0=Not at all, 1=Just a little, 2=Somewhat, 3=A lot
gen not =1
label var not "Not at all"

gen little =1
label var little "Just a little"

gen some =1
label var some "Somewhat"

gen alot =1
label var alot "A lot"


matrix B = A[1..4, 1..2]
matrix list B


/*

B[5,2]
          nobs   share
   not    5476    18.3
little   13555    22.2
  some   22019      23
  alot   61810    36.5

*/


esttab  matrix(B, fmt(%9.0fc %9.0f)) using $OUTPATH/$tabname.rtf, title("Table 2. Frequency of Trust Responses.") ///
collabels(N %, lhs({\i Trust response})) addnotes("{\i Notes:} Frequency of each response. All respondents from Afrobarometer survey rounds 2-7 are included. The question asked is 'How much do you trust each of the following, or haven't you heard enough about them to say: The President/Prime Minister?' Pre-defined answers and corresponding values are: Not at all (0), Just a little (1), Somewhat (2), and A lot (3). ") ///
noobs nonumber nomtitles label compress nogaps replace 
